package part15_中介者模式_智能家居;

import java.util.HashMap;

/**
 * @ClassName: ConcreteMediator
 * @Author: AllenSun
 * @Date: 2020/3/8 22:22
 */
public class ConcreteMediator extends Mediator {

    //集合，放入所有的同事对象
    private HashMap<String, Colleague > colleagueMap;
    private HashMap<String,String > interMap;

    public ConcreteMediator() {
        colleagueMap = new HashMap<String,Colleague>();
        interMap = new HashMap<String,String>();
    }

    @Override
    public void Register(String colleagueName, Colleague colleague) {
        colleagueMap.put(colleagueName,colleague);
        if(colleague instanceof Alarm){
            interMap.put("Alarm",colleagueName);
        } else if(colleague instanceof CoffeeMachine){
            interMap.put("CoffeeMachine",colleagueName);
        } else if(colleague instanceof TV){
            interMap.put("TV",colleagueName);
        } else if(colleague instanceof Curtains){
            interMap.put("Curtains",colleagueName);
        }
    }

    /**具体中介者的核心方法
     * 根据得到的消息，完成对应的任务
     * 中介者在这个份昂发，协调各个具体的同事对象，完成任务
     * @MethodName: GetMessage
     * @Author: AllenSun
     * @Date: 2020/3/8 22:37
     */
    @Override
    public void GetMessage(int stateChange, String colleagueName) {
        //处理闹钟发出的声音
        if(colleagueMap.get(colleagueName) instanceof Alarm){
            if(stateChange==0){
                ((CoffeeMachine)(colleagueMap.get(interMap.get("CoffeeMachine")))).StartCoffee();
                ((TV)(colleagueMap.get(interMap.get("TV")))).StartTv();
            } else if(stateChange==1){
                ((TV)(colleagueMap.get(interMap.get("TV")))).StopTv();
            }
        } else if(colleagueMap.get(colleagueName) instanceof CoffeeMachine){
            ((Curtains)(colleagueMap.get(interMap.get("Curtains")))).UpCurtains();
        } else if(colleagueMap.get(colleagueName) instanceof TV){
        } else if(colleagueMap.get(colleagueName) instanceof Curtains){
        }
    }

    @Override
    public void SendMessage() {

    }
}
